﻿//创建时间: 2010-10-29
//创建作者: 李 城
//功能说明: 发布引擎的入口处
//最后修改: 2010-10-29 

#define PublishAccessDebuf
#undef PublishAccessDebuf

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Collections;
using System.Text.RegularExpressions;

using TRPOP.Common;
using TRPOP.CMS.Template;
using TRPOP.CMS.Model;
using TRPOP.CMS.Business;
using TRPOP.Config;
using TRPOP.CMS.Plugin;
using TRPOP.CMS.Template.GenerateCS;
using TRPOP.Cache;

namespace TRPOP.CMS.Publish
{
    public class PublishAccess
    {
        /// <summary>
        /// 缓存处理实例
        /// </summary>
        public static ICache mICache = ICacheAccess.GetInstance();

        /// <summary>
        /// 初始化模板引擎
        /// </summary>
        /// <param name="oDictionary"></param>
        /// <param name="ContentIdOut"></param>
        public static void InitTemplateEngeen(Dictionary<string, string> oDictionary, int ContentIdOut)
        {
            if (oDictionary.ContainsKey("InfoClickSubmit"))
            {
                oDictionary["InfoClickSubmit"] = SYSConfig.SystemVar_InfoClickSubmitURL.ToLower();
            }
            else
            {
                oDictionary.Add("InfoClickSubmit", SYSConfig.SystemVar_InfoClickSubmitURL.ToLower());
            }
            using (TRPOP.CMS.Plugin.PluginAssistForTemplate oPluginAssist = new PluginAssistForTemplate())
            {
                oPluginAssist.InitTemplateEngeen(oDictionary, ContentIdOut.ToString());
            }
        }

        #region 发布各种类型的页面 发布为物理文件

        /// <summary>
        /// 通用的方法，根据提供的参数，生成页面 各种类型页面的生成均调用了此方法
        /// </summary>
        /// <param name="oTemplateDllPageInfo"></param>
        /// <param name="oNodeInfo"></param>
        /// <param name="strRoot"></param>
        /// <param name="strFileName"></param>
        /// <param name="strFileExtName"></param>
        public static void PubPageByTemplateDllPageInfo(TRPOP.CMS.Template.GenerateCS.TemplateDllPageInfo oTemplateDllPageInfo, NodeInfo oNodeInfo, string strRoot, string strFileName, string strFileExtName)
        {
            TRPOP.CMS.Template.GenerateCS.Access oAccsss = new Template.GenerateCS.Access();
            if (!FileUtil.IsExist(oTemplateDllPageInfo.strTemplateCsFilePath) || !FileUtil.IsExist(oTemplateDllPageInfo.strTemplateDLLPath))
            {
                oAccsss.GenerateCSFile(oTemplateDllPageInfo);//生成CS文件
                oAccsss.GenerateDLLFile(oTemplateDllPageInfo);//生成DLL
                TRPOP.CMS.Template.ExecuteTemplate.ReMoveOneDllFromCache(oTemplateDllPageInfo);//从缓存中删除dll信息
            }

            object obj = null;//取出已解析过的数据，设定为 obj

            if (FileUtil.IsExist(oTemplateDllPageInfo.strTemplateDLLPath))
            {

                InitTemplateEngeen(oTemplateDllPageInfo.oPageVars, oTemplateDllPageInfo.intCurrentContentID);//预变量添加

#if PublishAccessDebuf

                DateTime dtStart = DateTime.Now;

                oTemplateDllPageInfo = oAccsss.ExecuteteDll(oTemplateDllPageInfo);//执行DLL

                DateTime dtEnd = DateTime.Now;
                string strTimeSpan = GetTimeSpan(dtStart, dtEnd, oTemplateDllPageInfo);

                if (oTemplateDllPageInfo.strErrorInfo.IsEmpty() == false)
                {
                    obj = oTemplateDllPageInfo.strErrorInfo;
                }
                else if (oTemplateDllPageInfo.enumTemplateType == EnumList.TemplateType.ContentPage)
                {
                    if (oTemplateDllPageInfo.oContantStrArray.Count > 0)
                    {
                        obj = SaveTimeSpan(oTemplateDllPageInfo.oContantStrArray, strTimeSpan);
                    }
                    else
                    {
                        obj = SaveTimeSpan(oTemplateDllPageInfo.strBuildHtml.ToString(), strTimeSpan);
                    }
                }
                else
                    obj = SaveTimeSpan(oTemplateDllPageInfo.strBuildHtml.ToString(), strTimeSpan);

#else
                oTemplateDllPageInfo = oAccsss.ExecuteteDll(oTemplateDllPageInfo);//执行DLL

                if (oTemplateDllPageInfo.strErrorInfo.IsEmpty() == false)
                {
                    obj = oTemplateDllPageInfo.strErrorInfo;
                }
                else if (oTemplateDllPageInfo.enumTemplateType == EnumList.TemplateType.ContentPage)
                {
                    if (oTemplateDllPageInfo.oContantStrArray.Count > 0)
                    {
                        obj = oTemplateDllPageInfo.oContantStrArray;
                    }
                    else
                    {
                        obj = oTemplateDllPageInfo.strBuildHtml.ToString();
                    }
                }
                else
                    obj = oTemplateDllPageInfo.strBuildHtml.ToString();
#endif
            }


            //如果没有分页，但是页次却大于1，则不再写文件
            if (oTemplateDllPageInfo.IsFindPager == false && oTemplateDllPageInfo.intListPagePubIndex > 1)
                return;
            //根据提取出来的数据生成相关的页面
            if (obj != null)
            {
                PubBase.WordReplaceForPub(ref obj, PubBase.GetReplaceList(oNodeInfo));//根据结点设置，替换需要过滤的字符
                PubBase.PubPages(obj, strRoot, strFileName, strFileExtName, oTemplateDllPageInfo.intListPagePubIndex); //生成页面
            }

        }

        /// <summary>
        /// 发布内容页 并更改信息发布状态
        /// </summary>
        /// <param name="oNodeInfo">结点实体</param>
        /// <param name="oContentInfo">内容实体</param>
        /// <param name="intContentPageLength">内容分页长度限制</param>
        /// <param name="oContentTable">内容扩展信息</param>
        /// <param name="strContentTableIndexFiled">内容模型的内容字段</param>
        public static void PubOneContentPage(int intContentid)
        {
            if (intContentid <= 0)
                return;

            ContentManage mContentManage = new ContentManage();
            ContentInfo oContentInfo = mContentManage.GetInfoById(intContentid);
            //如果内容信息实体为空
            if (oContentInfo == null)
                return;
            NodeInfo oNodeInfo = new NodeManage().GetInfoById(oContentInfo.NodeId);//结点信息的获取
            DataTable oContentTable = ITemplateAccess.GetIDalInstance().GetContentWithImgResource(oContentInfo.ContentId.ToString());
            if (oContentTable == null || oContentTable.Rows.Count <= 0 || oNodeInfo == null)//如果查询不到信息
                return;
            ModelFieldInfo modelFieldInfo = new ModelFieldManage().GetTableMainFieldByNodeId(oContentInfo.NodeId);//内容模型信息的获取
            if (modelFieldInfo == null || modelFieldInfo.IsMainField == false)//如果内容模型字段没有主字段
            {
                throw new Exception("没有设定主内容字段，发布信息时出错");
            }

            mContentManage.CreateURL(oNodeInfo, oContentInfo);//更新信息的URL

            //如果不对外发布
            if (oNodeInfo.ContentPubTypeId == (int)TRPOP.Common.ContentPubType.EnumElement.NotOutPub)
                return;
            // 如果有外部链接  如果信息的URL为空  如果不是静态发布 如果索引链接 如果是外链接
            if (oContentInfo.ExtraUrl.IsEmpty() == false || oContentInfo.Url.IsEmpty() || oNodeInfo.ContentPubTypeId != (int)TRPOP.Common.ContentPubType.EnumElement.StaticPub || oContentInfo.Type == (int)TRPOP.Common.LinkType.EnumElement.IndexLink || oContentInfo.Type == (int)TRPOP.Common.LinkType.EnumElement.OutLink)
            {
                oContentInfo.PubStatus = (int)PubStatus.EnumElement.Publish;
                mContentManage.Save(oContentInfo);//仅仅更改发布状态
                return;
            }

            //  如果静态发布页面 生成页面

            //模板文件路径、生成页面文件名 扩展名 模板 等的获取和处理 开始
            Match oMatchRoot = CommonRegex.MatchPubFile(mContentManage.GetContentInfoPSNPath(oContentInfo));
            if (oMatchRoot.Success == false)
                return;
            string strRoot = oMatchRoot.Groups["root"].Value;//文件夹
            string strFileName = oMatchRoot.Groups["filename"].Value;//文件名
            string strFileExtName = oMatchRoot.Groups["extname"].Value;//扩展名.html
            string strTemplateCurrentFolder = string.Empty;//模板所在的当前路径
            string strTemplate = string.Empty;//模板文件名
            Match oMatchTemp = null;
            if (oContentInfo.Template.IsEmpty() && !oNodeInfo.DetailTemplate.IsEmpty())
            {
                oMatchTemp = CommonRegex.MatchPubFile(oNodeInfo.DetailTemplate);
                strTemplate = oNodeInfo.DetailTemplate;
            }
            else if (!oContentInfo.Template.IsEmpty())
            {
                oMatchTemp = CommonRegex.MatchPubFile(oContentInfo.Template);
                strTemplate = oContentInfo.Template;
            }
            if (oMatchTemp == null || oMatchTemp.Success == false)
                return;
            strTemplateCurrentFolder = oMatchTemp.Groups["root"].ToString();
            //模板文件路径、生成页面文件名 扩展名 模板 等的或获取和处理 结束

            // 动态生成cs、 dll文件，并执行DLL

            TRPOP.CMS.Template.GenerateCS.TemplateDllPageInfo oTemplateDllPageInfo = new Template.GenerateCS.TemplateDllPageInfo();

            oTemplateDllPageInfo.intCurrentContentID = oContentInfo.ContentId;
            oTemplateDllPageInfo.intCurrentNodeID = oContentInfo.NodeId;
            oTemplateDllPageInfo.intCurrentNodeParentID = oNodeInfo.ParentId;
            oTemplateDllPageInfo.intContentPageLength = SYSConfig.SystemVar_ContentPageLength;
            oTemplateDllPageInfo.strCurrentFolder = strTemplateCurrentFolder;
            oTemplateDllPageInfo.strContentMainFied = modelFieldInfo.FieldName;
            oTemplateDllPageInfo.enumTemplateType = EnumList.TemplateType.ContentPage;
            oTemplateDllPageInfo.strTemplateFilePath = Common.Util.GetMapPath(strTemplate);
            oTemplateDllPageInfo.strTemplateCsFilePath = Common.Util.GetMapPath(strTemplate + ".cs");
            oTemplateDllPageInfo.strTemplateDLLPath = Common.Util.GetMapPath(strTemplate + ".dll");
            oTemplateDllPageInfo.strPageName = oContentInfo.Url.Trim().Remove(oContentInfo.Url.Trim().LastIndexOf("."));
            oTemplateDllPageInfo.strPageExtName = strFileExtName;
            oTemplateDllPageInfo.strlistPageRegName = SYSConfig.SystemVar_listAutoPage;
            oTemplateDllPageInfo.strMainField = modelFieldInfo.FieldName;
            oTemplateDllPageInfo.strPageingType = oNodeInfo.Pager;
            oTemplateDllPageInfo.oContentInfoRow = oContentTable.Rows[0];

            //生成页面
            PubPageByTemplateDllPageInfo(oTemplateDllPageInfo, oNodeInfo, strRoot, strFileName, strFileExtName);

            //更改 保存 发布状态
            oContentInfo.PubStatus = (int)PubStatus.EnumElement.Publish;
            (new TRPOP.CMS.Business.ContentManage()).Save(oContentInfo);
        }

        /// <summary>
        /// 列表页判断是否发布页面成功
        /// </summary>
        /// <param name="intPageIndex"></param>
        /// <param name="oTemplateDllPageInfo"></param>
        /// <returns></returns>
        private static bool CheckIfPubOK(int intPageIndex, TRPOP.CMS.Template.GenerateCS.TemplateDllPageInfo oTemplateDllPageInfo)
        {
            if (oTemplateDllPageInfo.IsFindPager)//分页
            {
                //if (oTemplateDllPageInfo.IsCurrentPageDataError)//分页数据不存在
                //    return false;
                return true;
            }
            else if (intPageIndex > 1)
                return false;
            else
                return oTemplateDllPageInfo.strBuildHtml.Length > 0;
        }

        /// <summary>
        /// 发布结点首页
        /// </summary>
        /// <param name="oNodeInfo"></param>
        /// <param name="intPageIndex">页面生成的起始位置 1开始</param>
        /// <param name="intPageNum">生成页面的总数目</param>
        /// <returns>如果达到预期的生成效果，则返回true </returns>
        public static bool PubOneNodeIndexPage(NodeInfo oNodeInfo, int intPageIndex)
        {
            //动态发布
            if (oNodeInfo.ContentPubTypeId == (int)TRPOP.Common.ContentPubType.EnumElement.DynamicPub)
            {
                return true;
            }
            //不对外发布  首页名为空 首页模板为空 不是静态发布
            else if (oNodeInfo.ContentPubTypeId == (int)TRPOP.Common.ContentPubType.EnumElement.NotOutPub || oNodeInfo.IndexName.IsEmpty() || oNodeInfo.IndexTemplate.IsEmpty() || oNodeInfo.ContentPubTypeId != (int)TRPOP.Common.ContentPubType.EnumElement.StaticPub)
                return false;
            //模板文件路径、生成页面文件名 扩展名 模板 等的获取和处理 开始
            NodeManage oNodeManage = new NodeManage();
            string strFileRoot = oNodeManage.GetIndexPSNPath(oNodeInfo).Trim();//生成的目录  /html/news/
            if (strFileRoot.Trim().EndsWith("/") == false)
                strFileRoot = strFileRoot.Trim() + "/";
            string strFileExtName = oNodeInfo.IndexName.Substring(oNodeInfo.IndexName.LastIndexOf("."));//扩展名
            string strFilename = oNodeInfo.IndexName.Substring(0, oNodeInfo.IndexName.LastIndexOf("."));//文件名 不带后缀
            string strTemplateCurrentFolder = string.Empty;//模板所在目录
            string strTemplate = string.Empty;//模板
            Match oMatchTemp = CommonRegex.MatchPubFile(oNodeInfo.IndexTemplate);
            if (oMatchTemp.Success == false)
                return false;
            strTemplateCurrentFolder = oMatchTemp.Groups["root"].ToString();
            strTemplate = oNodeInfo.IndexTemplate;
            //模板文件路径、生成页面文件名 扩展名 模板 等的获取和处理 结束

            //页面信息实体

            // 动态生成cs、 dll文件，并执行DLL
            TRPOP.CMS.Template.GenerateCS.TemplateDllPageInfo oTemplateDllPageInfo = new Template.GenerateCS.TemplateDllPageInfo();

            oTemplateDllPageInfo.strPageName = oNodeInfo.Url.Trim().Contains(".") ? oNodeInfo.Url.Trim().Remove(oNodeInfo.Url.Trim().LastIndexOf(".")) : oNodeInfo.Url.Trim();
            oTemplateDllPageInfo.intListPagePubIndex = intPageIndex;
            oTemplateDllPageInfo.intListPagePubCount = SYSConfig.SystemVar_listPageCount;
            oTemplateDllPageInfo.intCurrentNodeID = oNodeInfo.NodeId;
            oTemplateDllPageInfo.intCurrentNodeParentID = oNodeInfo.ParentId;
            oTemplateDllPageInfo.intContentPageLength = SYSConfig.SystemVar_ContentPageLength;
            oTemplateDllPageInfo.strCurrentFolder = strTemplateCurrentFolder;
            oTemplateDllPageInfo.enumTemplateType = EnumList.TemplateType.IndexPage;
            oTemplateDllPageInfo.strTemplateFilePath = Common.Util.GetMapPath(strTemplate);
            oTemplateDllPageInfo.strTemplateCsFilePath = Common.Util.GetMapPath(strTemplate + ".cs");
            oTemplateDllPageInfo.strTemplateDLLPath = Common.Util.GetMapPath(strTemplate + ".dll");
            oTemplateDllPageInfo.strPageExtName = strFileExtName;
            oTemplateDllPageInfo.strlistPageRegName = SYSConfig.SystemVar_listAutoPage;
            oTemplateDllPageInfo.strPageingType = oNodeInfo.Pager;

            //生成页面
            PubPageByTemplateDllPageInfo(oTemplateDllPageInfo, oNodeInfo, strFileRoot, strFilename, strFileExtName);

            return CheckIfPubOK(intPageIndex, oTemplateDllPageInfo);
        }

        /// <summary>
        /// 结点附加发布
        /// </summary>
        /// <param name="oNodeInfo"></param>
        /// <param name="intPageIndex">页面生成的起始位置 1开始</param>
        /// <param name="intPageNum">生成页面的总数目</param>
        /// <param name="oExtra">附加发布实体</param>
        /// <returns></returns>
        public static bool PubOneNodeExtraPage(NodeInfo oNodeInfo, int intPageIndex, NodeAddionalPubInfo oExtra)
        {
            // 不对外发布  附加发布页面名为空 模板文件为空 文件名不含. ULR不含.
            if (oNodeInfo.ContentPubTypeId == (int)TRPOP.Common.ContentPubType.EnumElement.NotOutPub || oExtra.PageName.IsEmpty() || oExtra.Template.IsEmpty() || oExtra.PageName.Contains(".") == false || oExtra.Url.Contains(".") == false)
                return false;

            //静态生成页面

            //模板文件路径、生成页面文件名 扩展名 模板 等的获取和处理
            NodeAddionalPubManage oNodeAddionalPubManage = new NodeAddionalPubManage();
            string strFileRoot = oNodeAddionalPubManage.GetPubInfoPSNPath(oExtra).Trim();//生成的目录
            if (strFileRoot.EndsWith("/") == false)
                strFileRoot = strFileRoot + "/";
            int intIndexOfPoint = oExtra.PageName.Trim().LastIndexOf(".");
            string strFilename = oExtra.PageName.Trim().Remove(intIndexOfPoint);//文件名 不带后缀
            string strFileExtName = oExtra.PageName.Trim().Substring(intIndexOfPoint);//扩展名
            Match oMatchTemp = CommonRegex.MatchPubFile(oExtra.Template);
            if (oMatchTemp.Success == false)
                return false;
            string strTemplateCurrentFolder = oMatchTemp.Groups["root"].ToString();//模板所在目录
            string strTemplate = oExtra.Template;//模板

            // 动态生成cs、 dll文件，并执行DLL
            TRPOP.CMS.Template.GenerateCS.TemplateDllPageInfo oTemplateDllPageInfo = new Template.GenerateCS.TemplateDllPageInfo();

            oTemplateDllPageInfo.strPageName = oExtra.Url.Trim().Remove(oExtra.Url.Trim().LastIndexOf("."));
            oTemplateDllPageInfo.intListPagePubIndex = intPageIndex;
            oTemplateDllPageInfo.intListPagePubCount = SYSConfig.SystemVar_listPageCount;
            oTemplateDllPageInfo.intCurrentNodeID = oNodeInfo.NodeId;
            oTemplateDllPageInfo.intCurrentNodeParentID = oNodeInfo.ParentId;
            oTemplateDllPageInfo.intContentPageLength = SYSConfig.SystemVar_ContentPageLength;
            oTemplateDllPageInfo.strCurrentFolder = strTemplateCurrentFolder;
            oTemplateDllPageInfo.enumTemplateType = EnumList.TemplateType.IndexPage;
            oTemplateDllPageInfo.strTemplateFilePath = Common.Util.GetMapPath(strTemplate);
            oTemplateDllPageInfo.strTemplateCsFilePath = Common.Util.GetMapPath(strTemplate + ".cs");
            oTemplateDllPageInfo.strTemplateDLLPath = Common.Util.GetMapPath(strTemplate + ".dll");
            oTemplateDllPageInfo.strPageExtName = strFileExtName;
            oTemplateDllPageInfo.strlistPageRegName = SYSConfig.SystemVar_listAutoPage;
            oTemplateDllPageInfo.strPageingType = oNodeInfo.Pager;

            //生成页面
            PubPageByTemplateDllPageInfo(oTemplateDllPageInfo, oNodeInfo, strFileRoot, strFilename, strFileExtName);

            return CheckIfPubOK(intPageIndex, oTemplateDllPageInfo);
        }

        #endregion

        #region 动态获取页面内容

        /// <summary>
        /// 调用模板引擎，获取解析后的HTML页面
        /// </summary>
        /// <param name="strHTMLTemplate"></param>
        /// <param name="oPageInfo"></param>
        /// <param name="oDictionary"></param>
        /// <returns></returns>
        public static object GetObjFromTemplateEngine(TRPOP.CMS.Template.GenerateCS.TemplateDllPageInfo oTemplateDllPageInfo)
        {
            TRPOP.CMS.Template.GenerateCS.Access oAccsss = new Template.GenerateCS.Access();
            if (!FileUtil.IsExist(oTemplateDllPageInfo.strTemplateCsFilePath) || !FileUtil.IsExist(oTemplateDllPageInfo.strTemplateDLLPath))
            {
                oAccsss.GenerateCSFile(oTemplateDllPageInfo);//生成CS文件
                oAccsss.GenerateDLLFile(oTemplateDllPageInfo);//生成DLL
                TRPOP.CMS.Template.ExecuteTemplate.ReMoveOneDllFromCache(oTemplateDllPageInfo);//从缓存中删除dll信息
            }

            InitTemplateEngeen(oTemplateDllPageInfo.oPageVars, oTemplateDllPageInfo.intCurrentContentID);//预变量添加

            DateTime dtStart = DateTime.Now;
            oTemplateDllPageInfo = oAccsss.ExecuteteDll(oTemplateDllPageInfo);//执行DLL
            DateTime dtEnd = DateTime.Now;

            object obj = oTemplateDllPageInfo.strBuildHtml.ToString();

#if PublishAccessDebuf
            obj = SaveTimeSpan(obj.ToString(), GetTimeSpan(dtStart, dtEnd));
#endif
            return obj;

        }

        /// <summary>
        /// 获取首页内容
        /// </summary>
        /// <param name="oNodeInfo">结点实体</param>
        /// <param name="intPageIndex">页码</param>
        /// <returns></returns>
        public static object GetOneNodeIndexPage(NodeInfo oNodeInfo, int intPageIndex)
        {
            //不对外发布  结点首页文件名为空 首页模板为空 首页文件名不包含.
            if (oNodeInfo.ContentPubTypeId == (int)TRPOP.Common.ContentPubType.EnumElement.NotOutPub || (oNodeInfo.IndexTemplate.IsEmpty()))
                return null;

            //获取内容

            //模板路径的处理
            

            // 首页 文件扩展名 文件名
            string strFileExtName = string.Empty;
            string strPageUrl = string.Empty;
            if (oNodeInfo.ContentPubTypeId == (int)TRPOP.Common.ContentPubType.EnumElement.StaticPub)
            {
                PSNManage oPSNManage = new PSNManage();
                int intIndexOfPoint = oNodeInfo.IndexName.LastIndexOf(".");
                strFileExtName = oNodeInfo.IndexName.Substring(intIndexOfPoint);//扩展名
                string strFilename = oNodeInfo.IndexName.Substring(0, intIndexOfPoint);//文件名 不带后缀
                strPageUrl = oPSNManage.GetPSNURLByPSNUrl(oNodeInfo.HtmlUrl);//  http://www.baidulcom/html/news
                if (strPageUrl.EndsWith("/") == false)
                {
                    strPageUrl += "/";
                }
                strPageUrl = strPageUrl + strFilename;
            }
            else
            {
                strPageUrl = oNodeInfo.Url;
                strFileExtName = ".aspx";
            }

            // 模板所在目录 模板文件 
            Match oMatchTemp = CommonRegex.MatchPubFile(oNodeInfo.IndexTemplate);
            if (oMatchTemp.Success == false)
                return null;
            string strTemplateCurrentFolder = oMatchTemp.Groups["root"].ToString();//模板所在目录
            string strTemplate = oNodeInfo.IndexTemplate;//模板

            // 动态生成cs、 dll文件，并执行DLL
            TRPOP.CMS.Template.GenerateCS.TemplateDllPageInfo oTemplateDllPageInfo = new Template.GenerateCS.TemplateDllPageInfo();

            oTemplateDllPageInfo.strPageName = strPageUrl;
            oTemplateDllPageInfo.strPageExtName = strFileExtName;
            oTemplateDllPageInfo.intListPagePubIndex = intPageIndex;
            oTemplateDllPageInfo.intListPagePubCount = SYSConfig.SystemVar_listPageCount;
            oTemplateDllPageInfo.intCurrentNodeID = oNodeInfo.NodeId;
            oTemplateDllPageInfo.intCurrentNodeParentID = oNodeInfo.ParentId;
            oTemplateDllPageInfo.intContentPageLength = SYSConfig.SystemVar_ContentPageLength;
            oTemplateDllPageInfo.strCurrentFolder = strTemplateCurrentFolder;
            oTemplateDllPageInfo.enumTemplateType = EnumList.TemplateType.IndexPage;
            oTemplateDllPageInfo.strTemplateFilePath = Common.Util.GetMapPath(strTemplate);
            oTemplateDllPageInfo.strTemplateCsFilePath = Common.Util.GetMapPath(strTemplate + ".cs");
            oTemplateDllPageInfo.strTemplateDLLPath = Common.Util.GetMapPath(strTemplate + ".dll");
            oTemplateDllPageInfo.strlistPageRegName = SYSConfig.SystemVar_listAutoPage;
            oTemplateDllPageInfo.strPageingType = oNodeInfo.Pager;

            //返回页面内容
            InitTemplateEngeen(oTemplateDllPageInfo.oPageVars, 0);            //初始化模板引擎
            object obj = GetObjFromTemplateEngine(oTemplateDllPageInfo);//获取生成的页面
            PubBase.WordReplaceForPub(ref obj, PubBase.GetReplaceList(oNodeInfo));             //替换字符串
            return obj;

        }

        /// <summary>
        /// 获取内容评论列表
        /// </summary>
        /// <param name="oNodeInfo">信息实体</param>
        /// <param name="intPageIndex">页码</param>
        /// <returns></returns>
        public static object GetOneContentRecPage(ContentInfo oContentInfo, int intPageIndex)
        {
            NodeInfo oNodeInfo;
            if (oContentInfo == null || (oNodeInfo = new NodeManage().GetInfoById(oContentInfo.NodeId)) == null)
                return null;
            RecomTemplateInfo oRecomTemplateInfo = new RecomTemplateManage().GetInfoById(oContentInfo.NodeId);
            //不对外发布  模板实例为空  模板为空  首页名  首页模板
            if (oNodeInfo.ContentPubTypeId == (int)TRPOP.Common.ContentPubType.EnumElement.NotOutPub || oRecomTemplateInfo == null || oRecomTemplateInfo.TemplateRoot.IsEmpty() || oNodeInfo.IndexName.IsEmpty() || oNodeInfo.IndexTemplate.IsEmpty())
            {
                return null;
            }

            Match oMatchTemp = CommonRegex.MatchPubFile(oRecomTemplateInfo.TemplateRoot);
            if (oMatchTemp.Success == false)
                return null;
            string strTemplateCurrentFolder = oMatchTemp.Groups["root"].ToString();//模板所在目录
            string strTemplate = oRecomTemplateInfo.TemplateRoot;//模板

            TRPOP.CMS.Template.GenerateCS.TemplateDllPageInfo oTemplateDllPageInfo = new Template.GenerateCS.TemplateDllPageInfo();
            DataTable oContentTable = ITemplateAccess.GetIDalInstance().GetContentWithImgResource(oContentInfo.ContentId.ToString());
            oTemplateDllPageInfo.intListPagePubIndex = intPageIndex;
            oTemplateDllPageInfo.intListPagePubCount = SYSConfig.SystemVar_listPageCount;
            oTemplateDllPageInfo.intCurrentContentID = oContentInfo.ContentId;
            oTemplateDllPageInfo.intCurrentNodeID = oNodeInfo.NodeId;
            oTemplateDllPageInfo.intCurrentNodeParentID = oNodeInfo.ParentId;
            oTemplateDllPageInfo.intContentPageLength = SYSConfig.SystemVar_ContentPageLength;
            oTemplateDllPageInfo.strCurrentFolder = strTemplateCurrentFolder;
            oTemplateDllPageInfo.enumTemplateType = EnumList.TemplateType.RecPage;
            oTemplateDllPageInfo.strTemplateFilePath = Common.Util.GetMapPath(strTemplate);
            if (oContentTable != null && oContentTable.Rows.Count > 0)
                oTemplateDllPageInfo.oContentInfoRow = oContentTable.Rows[0];
            oTemplateDllPageInfo.strTemplateCsFilePath = Common.Util.GetMapPath(strTemplate + ".cs");
            oTemplateDllPageInfo.strTemplateDLLPath = Common.Util.GetMapPath(strTemplate + ".dll");
            oTemplateDllPageInfo.strlistPageRegName = SYSConfig.RecommentConfigerInfo.URL_List;
            oTemplateDllPageInfo.strPageingType = oNodeInfo.Pager;

            //生成页面
            InitTemplateEngeen(oTemplateDllPageInfo.oPageVars, 0);  //初始化模板引擎
            object obj = GetObjFromTemplateEngine(oTemplateDllPageInfo);//获取解析后的页面内容
            PubBase.WordReplaceForPub(ref obj, PubBase.GetReplaceList(oNodeInfo));//替换字符串
            if (SYSConfig.RecommentConfigerInfo.EnableTextReplace)
                PubBase.WordReplaceForPub(ref obj, SYSConfig.RecommentConfigerInfo.TextReplace, SYSConfig.RecommentConfigerInfo.TextReplaceList.Split(','));
            return obj;
        }

        /// <summary>
        /// 获取内容
        /// </summary>
        /// <param name="intContentid"></param>
        /// <returns></returns>
        public static object GetOneContentPage(int intContentid)
        {
            object obj = new object();
            if (intContentid <= 0)
                return obj;
            //关于内容 结点 基本信息的获取
            ContentManage mContentManage = new ContentManage();
            ContentInfo oContentInfo = new ContentInfo();
            NodeInfo oNodeInfo = new NodeInfo();
            int intContentPageLength = SYSConfig.SystemVar_ContentPageLength;
            oContentInfo = mContentManage.GetInfoById(intContentid);
            if (oContentInfo == null)
                return obj;
            DataTable oContentTable = ITemplateAccess.GetIDalInstance().GetContentWithImgResource(oContentInfo.ContentId.ToString());
            ModelFieldInfo modelFieldInfo = new ModelFieldManage().GetTableMainFieldByNodeId(oContentInfo.NodeId);
            if (modelFieldInfo == null)
                return obj;
            oNodeInfo = new NodeManage().GetInfoById(oContentInfo.NodeId);
            //更新url
            mContentManage.CreateURL(oNodeInfo, oContentInfo);
            //关于模板的 基本信息的获取

            //针对文件路径、url地址等的处理
            string strUrl = string.Empty;
            string strRoot = string.Empty;
            string strFileName = string.Empty;
            string strFileExtName = string.Empty;
            Match oMatchUrl = CommonRegex.MatchHttpUrl(oContentInfo.Url);
            if (oMatchUrl.Success && oNodeInfo.ContentPubTypeId == (int)TRPOP.Common.ContentPubType.EnumElement.StaticPub)
                strUrl = oMatchUrl.Groups["url"].Value;
            else
                strUrl = oNodeInfo.ContentPortalURL;
            Match oMatchRoot = CommonRegex.MatchPubFile(oMatchUrl.Groups["root"].Value);
            if (oMatchRoot.Success && oNodeInfo.ContentPubTypeId == (int)TRPOP.Common.ContentPubType.EnumElement.StaticPub)
            {
                strRoot = oMatchRoot.Groups["root"].Value;
                strFileName = oMatchRoot.Groups["filename"].Value;
                strFileExtName = oMatchRoot.Groups["extname"].Value;
            }
            else if (oMatchRoot.Success == false && oNodeInfo.ContentPubTypeId == (int)TRPOP.Common.ContentPubType.EnumElement.StaticPub)
            {
                return obj;
            }

            string strTemplate = "";
            //针对模板路径的处理
            Match oMatchTemp = null;
            if (oContentInfo.Template.IsEmpty())
            {
                if (oNodeInfo.DetailTemplate.IsEmpty())
                    return null;
                oMatchTemp = CommonRegex.MatchPubFile(oNodeInfo.DetailTemplate);
                strTemplate = oNodeInfo.DetailTemplate;
            }
            else
            {
                oMatchTemp = CommonRegex.MatchPubFile(oContentInfo.Template);
                strTemplate = oContentInfo.Template;
            }
            if (oMatchTemp.Success == false)
                return false;
            string strTemplateCurrentFolder = oMatchTemp.Groups["root"].ToString();

            //模板信息实体
            TRPOP.CMS.Template.GenerateCS.TemplateDllPageInfo oTemplateDllPageInfo = new Template.GenerateCS.TemplateDllPageInfo();

            oTemplateDllPageInfo.intCurrentContentID = oContentInfo.ContentId;
            oTemplateDllPageInfo.intCurrentNodeID = oContentInfo.NodeId;
            oTemplateDllPageInfo.intCurrentNodeParentID = oNodeInfo.ParentId;
            oTemplateDllPageInfo.intContentPageLength = intContentPageLength;
            oTemplateDllPageInfo.strCurrentFolder = strTemplateCurrentFolder;
            oTemplateDllPageInfo.strContentMainFied = modelFieldInfo.FieldName;
            oTemplateDllPageInfo.enumTemplateType = EnumList.TemplateType.ContentPage;
            oTemplateDllPageInfo.strTemplateFilePath = Common.Util.GetMapPath(strTemplate);
            oTemplateDllPageInfo.strTemplateCsFilePath = Common.Util.GetMapPath(strTemplate + ".cs");
            oTemplateDllPageInfo.strTemplateDLLPath = Common.Util.GetMapPath(strTemplate + ".dll");
            oTemplateDllPageInfo.strPageName = strUrl + strRoot + strFileName;
            oTemplateDllPageInfo.strPageExtName = strFileExtName;
            oTemplateDllPageInfo.strlistPageRegName = SYSConfig.SystemVar_listAutoPage;
            oTemplateDllPageInfo.strMainField = modelFieldInfo.FieldName;
            oTemplateDllPageInfo.strPageingType = oNodeInfo.Pager;
            if (oContentTable != null && oContentTable.Rows.Count > 0)
                oTemplateDllPageInfo.oContentInfoRow = oContentTable.Rows[0];


            if (oNodeInfo.ContentPubTypeId == (int)TRPOP.Common.ContentPubType.EnumElement.DynamicPub)
            {
                oTemplateDllPageInfo.strPageName = oNodeInfo.ContentPortalURL;
                oTemplateDllPageInfo.strPageingType = "dynamicaccess";//动态访问
            }

            InitTemplateEngeen(oTemplateDllPageInfo.oPageVars, oContentInfo.ContentId);//初始化模板引擎
            obj = GetObjFromTemplateEngine(oTemplateDllPageInfo);//解析模板
            PubBase.WordReplaceForPub(ref obj, PubBase.GetReplaceList(oNodeInfo));//字符替换
            return obj;

        }

        /// <summary>
        /// 搜索列表
        /// </summary>
        /// <param name="oNodeInfo"></param>
        /// <param name="strKeys"></param>
        /// <param name="intPageIndex"></param>
        /// <returns></returns>
        public static object GetPageSearch(NodeInfo oNodeInfo, string strKeys, int intPageIndex)
        {
            Match oMatchTemp = CommonRegex.MatchPubFile(SYSConfig.SystemVar_PageSearchTemplate);
            if (oMatchTemp.Success == false)
                return null;
            string strTemplateCurrentFolder = oMatchTemp.Groups["root"].ToString();//模板所在目录
            string strTemplate = SYSConfig.SystemVar_PageSearchTemplate;//模板

            TRPOP.CMS.Template.GenerateCS.TemplateDllPageInfo oTemplateDllPageInfo = new Template.GenerateCS.TemplateDllPageInfo();

            oTemplateDllPageInfo.intListPagePubIndex = intPageIndex;
            oTemplateDllPageInfo.intListPagePubCount = SYSConfig.SystemVar_listPageCount;
            oTemplateDllPageInfo.intCurrentNodeID = oNodeInfo.NodeId;
            oTemplateDllPageInfo.intCurrentNodeParentID = oNodeInfo.ParentId;
            oTemplateDllPageInfo.intContentPageLength = SYSConfig.SystemVar_ContentPageLength;
            oTemplateDllPageInfo.strCurrentFolder = strTemplateCurrentFolder;
            oTemplateDllPageInfo.enumTemplateType = EnumList.TemplateType.SearchPage;
            oTemplateDllPageInfo.strTemplateFilePath = Common.Util.GetMapPath(strTemplate);
            oTemplateDllPageInfo.strTemplateCsFilePath = Common.Util.GetMapPath(strTemplate + ".cs");
            oTemplateDllPageInfo.strTemplateDLLPath = Common.Util.GetMapPath(strTemplate + ".dll");
            oTemplateDllPageInfo.strlistPageRegName = SYSConfig.SystemVar_PageSearchURL;
            oTemplateDllPageInfo.strPageingType = oNodeInfo.Pager;
            oTemplateDllPageInfo.strSearchPageKeys = strKeys;

            //生成页面
            InitTemplateEngeen(oTemplateDllPageInfo.oPageVars, 0);//初始化模板引擎
            object obj = GetObjFromTemplateEngine(oTemplateDllPageInfo);//解析模板
            PubBase.WordReplaceForPub(ref obj, PubBase.GetReplaceList(oNodeInfo));//字符替换
            return obj;
        }

        /// <summary>
        /// 搜索列表 高级搜索
        /// </summary>
        /// <param name="oNodeInfo"></param>
        /// <param name="strAdvancedSearchCondation"></param>
        /// <param name="intPageIndex"></param>
        /// <returns></returns>
        public static object GetPageAdvancedSearch(NodeInfo oNodeInfo, string strAdvancedSearchCondation, int intPageIndex)
        {
            Match oMatchTemp = CommonRegex.MatchPubFile(SYSConfig.SystemVar_PageSearchTemplate);
            if (oMatchTemp.Success == false)
                return null;
            string strTemplateCurrentFolder = oMatchTemp.Groups["root"].ToString();//模板所在目录
            string strTemplate = SYSConfig.SystemVar_PageSearchTemplate;//模板

            TRPOP.CMS.Template.GenerateCS.TemplateDllPageInfo oTemplateDllPageInfo = new Template.GenerateCS.TemplateDllPageInfo();

            oTemplateDllPageInfo.intListPagePubIndex = intPageIndex;
            oTemplateDllPageInfo.intListPagePubCount = SYSConfig.SystemVar_listPageCount;
            oTemplateDllPageInfo.intCurrentNodeID = oNodeInfo.NodeId;
            oTemplateDllPageInfo.intCurrentNodeParentID = oNodeInfo.ParentId;
            oTemplateDllPageInfo.intContentPageLength = SYSConfig.SystemVar_ContentPageLength;
            oTemplateDllPageInfo.strCurrentFolder = strTemplateCurrentFolder;
            oTemplateDllPageInfo.enumTemplateType = EnumList.TemplateType.SearchPage;
            oTemplateDllPageInfo.strTemplateFilePath = Common.Util.GetMapPath(strTemplate);
            oTemplateDllPageInfo.strTemplateCsFilePath = Common.Util.GetMapPath(strTemplate + ".cs");
            oTemplateDllPageInfo.strTemplateDLLPath = Common.Util.GetMapPath(strTemplate + ".dll");
            oTemplateDllPageInfo.strlistPageRegName = SYSConfig.SystemVar_PageSearchURL;
            oTemplateDllPageInfo.strPageingType = oNodeInfo.Pager;
            oTemplateDllPageInfo.strAdvancedSearchCondation = strAdvancedSearchCondation;

            //生成页面
            InitTemplateEngeen(oTemplateDllPageInfo.oPageVars, 0);//初始化模板引擎
            object obj = GetObjFromTemplateEngine(oTemplateDllPageInfo);//解析模板
            PubBase.WordReplaceForPub(ref obj, PubBase.GetReplaceList(oNodeInfo));//字符替换
            return obj;
        }

        /// <summary>
        /// 搜索列表 高级搜索
        /// </summary>
        /// <param name="oNodeInfo"></param>
        /// <param name="strAdvancedSearchCondation"></param>
        /// <param name="intPageIndex"></param>
        /// <param name="strPageSearchTemplate">自定义模板文件</param>
        /// <returns></returns>
        public static object GetPageAdvancedSearch(NodeInfo oNodeInfo, string strAdvancedSearchCondation, int intPageIndex, string strPageSearchTemplate)
        {

            Match oMatchTemp = CommonRegex.MatchPubFile(strPageSearchTemplate);
            if (oMatchTemp.Success == false)
                return null;
            string strTemplateCurrentFolder = oMatchTemp.Groups["root"].ToString();//模板所在目录
            string strTemplate = strPageSearchTemplate;//模板

            TRPOP.CMS.Template.GenerateCS.TemplateDllPageInfo oTemplateDllPageInfo = new Template.GenerateCS.TemplateDllPageInfo();

            oTemplateDllPageInfo.intListPagePubIndex = intPageIndex;
            oTemplateDllPageInfo.intListPagePubCount = SYSConfig.SystemVar_listPageCount;
            oTemplateDllPageInfo.intCurrentNodeID = oNodeInfo.NodeId;
            oTemplateDllPageInfo.intCurrentNodeParentID = oNodeInfo.ParentId;
            oTemplateDllPageInfo.intContentPageLength = SYSConfig.SystemVar_ContentPageLength;
            oTemplateDllPageInfo.strCurrentFolder = strTemplateCurrentFolder;
            oTemplateDllPageInfo.enumTemplateType = EnumList.TemplateType.SearchPage;
            oTemplateDllPageInfo.strTemplateFilePath = Common.Util.GetMapPath(strTemplate);
            oTemplateDllPageInfo.strTemplateCsFilePath = Common.Util.GetMapPath(strTemplate + ".cs");
            oTemplateDllPageInfo.strTemplateDLLPath = Common.Util.GetMapPath(strTemplate + ".dll");
            oTemplateDllPageInfo.strlistPageRegName = SYSConfig.SystemVar_PageSearchURL;
            oTemplateDllPageInfo.strPageingType = oNodeInfo.Pager;
            oTemplateDllPageInfo.strAdvancedSearchCondation = strAdvancedSearchCondation;

            //生成页面
            InitTemplateEngeen(oTemplateDllPageInfo.oPageVars, 0);//初始化模板引擎
            object obj = GetObjFromTemplateEngine(oTemplateDllPageInfo);//解析模板
            PubBase.WordReplaceForPub(ref obj, PubBase.GetReplaceList(oNodeInfo));//字符替换
            return obj;
        }

        /// <summary>
        /// prompt信息提示页 
        /// </summary>
        /// <param name="oNodeInfo"></param>
        /// <param name="strKeys"></param>
        /// <param name="intPageIndex"></param>
        /// <returns></returns>
        public static object GetPagePrompt(string strPrompt)
        {
            Match oMatchTemp = CommonRegex.MatchPubFile(SYSConfig.SystemVar_PagePromotTemplate);
            if (oMatchTemp.Success == false)
                return null;
            string strTemplateCurrentFolder = oMatchTemp.Groups["root"].ToString();//模板所在目录
            string strTemplate = SYSConfig.SystemVar_PagePromotTemplate;//模板

            TRPOP.CMS.Template.GenerateCS.TemplateDllPageInfo oTemplateDllPageInfo = new Template.GenerateCS.TemplateDllPageInfo();
            oTemplateDllPageInfo.strCurrentFolder = strTemplateCurrentFolder;
            oTemplateDllPageInfo.enumTemplateType = EnumList.TemplateType.NormalPage;
            oTemplateDllPageInfo.strTemplateFilePath = Common.Util.GetMapPath(strTemplate);
            oTemplateDllPageInfo.strTemplateCsFilePath = Common.Util.GetMapPath(strTemplate + ".cs");
            oTemplateDllPageInfo.strTemplateDLLPath = Common.Util.GetMapPath(strTemplate + ".dll");


            oTemplateDllPageInfo.oPageVars.Add("errorInfo", strPrompt);//将errorInfo 添加至模板引擎当中 

            return GetObjFromTemplateEngine(oTemplateDllPageInfo);//页面解析
        }

        #endregion

        #region 页面发布所用时间统计

        /// <summary>
        /// 获取时间间隔
        /// </summary>
        /// <param name="oStart"></param>
        /// <param name="oEnd"></param>
        /// <returns></returns>
        public static string GetTimeSpan(DateTime dtStart, DateTime dtEnd)
        {
            return "<!-- Execute Page: " + Convert.ToInt32(dtEnd.Subtract(dtStart).TotalMilliseconds) + "  -->" + System.Environment.NewLine;
        }

        /// <summary>
        /// 获取时间间隔
        /// </summary>
        /// <param name="oStart"></param>
        /// <param name="oEnd"></param>
        /// <returns></returns>
        public static string GetTimeSpan(DateTime dtStart, DateTime dtEnd, TemplateDllPageInfo oInfo)
        {
            string strReturn = "<!-- ";
            strReturn += "Execute Page: " + Convert.ToInt32(dtEnd.Subtract(dtStart).TotalMilliseconds) + "   ";
            strReturn += "Execute Page MainFunc: " + oInfo.intTotalTimeSpan.ToString() + "   ";
            strReturn += "Execute Page MainFunc GetData: " + oInfo.intDataTimeSpan.ToString() + "   ";
            strReturn += "Execute Page MainFunc PreOper: " + oInfo.intPreExecuteDataTimeSpan.ToString() + "   ";
            strReturn += "Execute Page MainFunc EndOper: " + oInfo.intEndExecuteDataTimeSpan.ToString() + "   ";
            strReturn += "  -->" + System.Environment.NewLine;
            return strReturn;
        }

        /// <summary>
        /// 将时间间隔显示到页面里
        /// </summary>
        /// <param name="strSource"></param>
        /// <param name="strTimeSpan"></param>
        /// <returns></returns>
        public static string SaveTimeSpan(string strSource, string strTimeSpan)
        {
            return strSource.Replace(@"</body>", strTimeSpan + @"</body>");
        }

        public static ArrayList SaveTimeSpan(ArrayList strSourceArray, string strTimeSpan)
        {
            for (int i = 0; i < strSourceArray.Count; i++)
            {
                strSourceArray[i] = SaveTimeSpan(strSourceArray[i].ToString(), strTimeSpan);
            }
            return strSourceArray;
        }

        #endregion

    }
}
